<?php
class Customer_Widgets_Customerinfo_Widget extends Tomato_Widget
{
    protected function _prepareShow()
    {
        $user_id = $this->_request->getParam('user_id');
        $this->_view->assign('user_id', $user_id);
        /**
        * Get connection to database
        **/
        $conn = Tomato_Db_Connection::factory()->getSlaveConnection();

        /**
        * Customer models access to data
        **/
        $customerDao = Tomato_Model_Dao_Factory::getInstance()->setModule('customer')->getCustomerDao();
        $customerDao->setDbConnection($conn);

        /**
         * Enterprise basic model access to db
         */
        $enterpriseDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getEnterpriseDao();
        $enterpriseDao->setDbConnection($conn);

        /**
        * Enterprise User model access to db
        */
        $userAccountDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getUserDao();
        $userAccountDao->setDbConnection($conn);

        /**
         * Get customer info
        **/
        $customer = null;
        if($user_id){
            $customer = $customerDao->getById($user_id);
        }
        $this->_view->assign('customer', $customer);

        /**
         * Get enterprise of user
         **/
         $enterprise = null;
         if($user_id){
            $userAccount = $userAccountDao->getByUser($user_id);
            if($userAccount){
                $enterprise = $enterpriseDao->getById($userAccount->enterprise_id);
            }
         }
         $this->_view->assign('enterprise', $enterprise);
    }
}
